unit diarionew;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, DB, DBTables, StdCtrls, Buttons, Grids, DBGrids;

type
  TFconvertediario = class(TForm)
    DBGrid1: TDBGrid;
    BitBtn1: TBitBtn;
    diariodbf: TTable;
    DataSource2: TDataSource;
    diariopa: TTable;
    DataSource1: TDataSource;
    BitBtn2: TBitBtn;
    diariodbfDATALA: TDateField;
    diariodbfDEVEDO: TSmallintField;
    diariodbfCREDOR: TSmallintField;
    diariodbfHPLANC: TSmallintField;
    diariodbfCOMPLE: TStringField;
    diariodbfVALORL: TFloatField;
    diariodbfMESANO: TStringField;
    diariodbfOPERADOR: TStringField;
    diariopaData: TDateField;
    diariopaLancamento: TFloatField;
    diariopaCredora: TStringField;
    diariopaDevedora: TStringField;
    diariopaHp: TFloatField;
    diariopaComplemento: TStringField;
    diariopaValor: TFloatField;
    diariopaUsuario: TStringField;
    diariopaReferencia: TStringField;
    diariopaConsolidado: TBooleanField;
    procedure BitBtn2Click(Sender: TObject);
    procedure BitBtn1Click(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Fconvertediario: TFconvertediario;

implementation

{$R *.dfm}

procedure TFconvertediario.BitBtn2Click(Sender: TObject);
begin
close;
end;

procedure TFconvertediario.BitBtn1Click(Sender: TObject);
var
contador : integer;
mdevedora, mcredora : string;
begin
diariopa.DisableControls;
contador := 0;
//diariopa.open;
diariopa.EmptyTable;
diariopa.close;
diariopa.open;
diariodbf.open;
diariodbf.First;

while not diariodbf.eof do
 begin
 mdevedora := copy(diariodbfdevedo.asstring,1,2) + '00' + copy(diariodbfdevedo.AsString,3,2);
 mcredora  := copy(diariodbfcredor.asstring,1,2) + '00' + copy(diariodbfcredor.AsString,3,2);
 diariopa.Append;
 diariopalancamento.value  := contador;
 diariopaData.value        := diariodbfdatala.value;
 diariopadevedora.value    := mdevedora;
 diariopacredora.value     := mcredora;
 diariopahp.value          := diariodbfhplanc.value;
 diariopacomplemento.value := diariodbfcomple.value;
 diariopavalor.value       := diariodbfvalorl.value;
 diariopausuario.value     := 'GOMIDE';
 diariopa.post;
 diariodbf.Next;
 contador := contador + 1;
end;
diariopa.First;
diariopa.EnableControls;
end;

end.
